package com.lyfei.ydc.api;

import com.lyfei.ydc.core.LocalUser;
import com.lyfei.ydc.core.interceptors.ScopeLevel;
import com.lyfei.ydc.domain.dto.SuccessDTO;
import com.lyfei.ydc.domain.entity.User;
import com.lyfei.ydc.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    private UserService userService;

    @PostMapping("/wx_info")
    @ScopeLevel
    public SuccessDTO updateUserInfo(@RequestBody Map<String,Object> user) {
        userService.updateUserWxInfo(user);
        return new SuccessDTO();
    }

    @GetMapping("/info")
    @ScopeLevel
    public Map<String, Object> getUserInfo() {
        Long userId = LocalUser.getUser().getId();
        User user = userService.getUserById(userId);
        return user.getWxProfileMap();
    }
}
